package com.manyiaby.view.viewutils;

import android.content.ClipData;
import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;

import com.manyiaby.welcome.ProxyApplication;

/**
 * Created by yx on 2017/8/1.
 */

public class CopyContentUtils {
    // 得到剪贴板管理器
    private static ClipboardManager cmb = (ClipboardManager) ProxyApplication.getInstance().getSystemService(Context.CLIPBOARD_SERVICE);

    /**
     * 实现文本复制功能
     */
    public static void copyPlainText(String roo) {
        //1.文字
        ClipData clip = ClipData.newPlainText(null, roo);
        //2.URI
//                Uri copyUri = Uri.parse("xxx");
//                ClipData clip = ClipData.newUri(context.getContentResolver(), "URI", copyUri);
        //3.Intent
//                Intent appIntent = new Intent(this, com.example.demo.myapplication.class);
//                ClipData clip = ClipData.newIntent("Intent",appIntent);
        // Set the clipboard's primary clip.
        cmb.setPrimaryClip(clip);
//        检查剪切板是否有数据，并取出数据
//        if (cmb.hasPrimaryClip()) {
//            cmb.getPrimaryClip().getItemAt(0).getText();
//        }


        ToastUtils.showToastApplication("复制成功");
    }

    /**
     * 实现Uri复制功能
     */
    public static void copyUri(Uri roo) {
        ClipData clip = ClipData.newUri(ProxyApplication.getInstance().getContentResolver(), "URI", roo);
        cmb.setPrimaryClip(clip);

        ToastUtils.showToastApplication("复制成功");
    }

    /**
     * 实现Intent复制功能
     */
    public static void copyIntent(Intent roo) {
        ClipData clip = ClipData.newIntent("Intent",roo);
        // Set the clipboard's primary clip.
        cmb.setPrimaryClip(clip);
        ToastUtils.showToastApplication("复制成功");
    }


}
